<?php
	class GateModel extends CI_Model {
		// 表名
		static $gateTable = "gate";
		static $gateTaskTable = "gate_task";

	    public function __construct() {
	        parent::__construct();
	    }

	    // 获取工作流流程信息
	    public function get_gate_info($deviceSn) {
	    	$where = "`is_delete` = 0 AND `device_sn`='{$deviceSn}'";
	    	$gateInfo = $this->db->where($where)->get(self::$gateTable)->row_array();
	    	return $gateInfo;
	    }

	    // 获取工作流流程列表
	    public function get_gate_task($params = ""){
	    	$where = "1 AND 1";
	    	// 分页
	    	if(isset($params['pageStart']) && isset($params['pageSize'])) $this->db->limit($params['pageSize'], $params['pageStart']);
	    	// 闸机ID
	    	if(isset($params['gateId'])) $where .= " AND `gate_id` = '{$params['gateId']}'";
	    	// 任务状态
			if(isset($params['taskState'])) $where .= " AND `task_state`='{$params['taskState']}'";
			// 是否已删除
	    	if(isset($params['isDelete'])) $where .= " AND `is_delete`='{$params['isDelete']}'";
	    	$this->db->where($where);
	    	// 是否只获取条数
	    	if(isset($params['getRowNumber'])) {
	    		$result = $this->db->count_all_results(self::$gateTaskTable);
	    	} else {
	    		$result = $this->db->get(self::$gateTaskTable)->result_array();	
	    	}
	    	return $result;
		}
	}